#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, k;
int c[16];
int a[N], sum[N];
int dp[1 << 16][16];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> k >> n;
  rep(i, 0, k - 1) cin >> c[i];
  rep(i, 1, n) cin >> a[i];
  rep(i, 1, n) sum[i] = sum[i - 1] + a[i];
  int mx = (1 << k) - 1;
  rep(s, 1, mx) {
    rep(i, 0, k - 1) {
      if (s & (1 << i)) {
        int t = s ^ (1 << i);
        if (!t) {
          int pos = upper_bound(sum + 1, sum + n + 1, c[i]) - sum - 1;
          dp[s][i] = sum[pos];
          continue;
        }
        rep(j, 0, k - 1) {
          if (t & (1 << j)) {
            int x = dp[t][j];
            if (x >= sum[n])
              dp[s][i] = max(dp[s][i], x + c[i]);
            else {
              x += c[i];
              int pos = upper_bound(sum + 1, sum + n + 1, x) - sum - 1;
              dp[s][i] = max(dp[s][i], sum[pos]);
            }
          }
        }
      }
    }
  }
  int ans = -1;
  rep(i, 0, k - 1) ans = max(ans, dp[mx][i] - sum[n]);
  cout << ans;
  return 0;
}